﻿using System.Diagnostics;

using zijian666.Converts.Abstractions;
using zijian666.Converts.Convertor.Base;
using zijian666.Converts.Core;

namespace XUnitTest;


public class UnitTest2
{
    public UnitTest2()
    {
        if (!Debugger.IsAttached)
        {
            DiagnosticListener.AllListeners.Subscribe(new DiagnosticObserver());
        }
    }

    [Fact]
    public void 自定义转换器()
    {
        var i = 11;
        var my = i.To<MyClass>();
        Assert.Equal(i, my.ID);
    }
    public class MyClass
    {
        public int ID { get; set; }
    }

    public class MyConvertor : AllowNullConvertor<MyClass>, IFrom<int, MyClass>
    {
        public ConvertResult<MyClass> From(IConvertContext context, int input)
        {
            return new MyClass() { ID = input };
        }
    }
}
